package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
)

// 结构体
type OurCustomTransport struct {
}

// 接口实现方法
func (t *OurCustomTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	// 处理一些事情 ...
	// 发起HTTP请求
	// 添加一些域到req.Header中
	return http.DefaultTransport.RoundTrip(req)
}

// 设置接口
func (t *OurCustomTransport) Client() *http.Client {
	return &http.Client{Transport: t}
}

func main() {
	t := &OurCustomTransport{
	//...
	}

	c := t.Client()
	resp, err := c.Get("http://10.42.0.59/health/")
	if err != nil {
		// 处理错误 ...
		return
	}
	defer resp.Body.Close()
	//	io.Copy(os.Stdout, resp.Body)
	body, err := ioutil.ReadAll(resp.Body)
	checkError(err)
	fmt.Println(string(body))
}

func checkError(err error) {
	if err != nil {
		fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
	}
}
